package org.lsy.service;

import org.apache.dubbo.config.annotation.Reference;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author liusy95
 * @version 1.0
 * @date 2020/8/18
 */
@Service
public class ValidateService {

    @Reference
    private UserService userService;

    private static final String DEFAULT_COOKIE = "token";

    public boolean validateToken(ServerHttpRequest request) {
        if (request.getCookies().containsKey(DEFAULT_COOKIE)) {
            String token = request.getCookies().get(DEFAULT_COOKIE).get(0).getValue();
            String info = userService.info(token);
            return !"未找到对应email".equals(info);
        }
        return false;
    }

}
